package partTwo;

import java.util.Scanner;

public class TestThrow {
    public static void main(String[] args) {
        method4();
    }

    public static void method4(){
        //1.复写刚刚可能会发生异常的代码
        System.out.println("请输入您要计算的第一个数据:");
        int a = new Scanner(System.in).nextInt();
        System.out.println("请输入您要计算的第二个数据:");
        int b = new Scanner(System.in).nextInt();
        try{
            double result = divide(a,b);
            System.out.println(result);
            //System.out.println(a/b);
        }catch (ArithmeticException e){
            System.out.println("不能除0是我们的错，请鞭笞我们吧！");
        }
    }

    private static double divide(int a,int b) {
        if(b == 0){
            ArithmeticException e = new ArithmeticException("/ by zero");
            throw e;//类似于return e;
        }
        return a/b;
    }

}